package com.group.eams.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.*;
import com.group.eams.pojo.entity.AssetAllocate;
import com.group.eams.pojo.entity.AssetClaim;
import com.group.eams.pojo.entity.AssetClaim;
import com.group.eams.pojo.vo.AssetClaimListVo;
import com.group.eams.pojo.vo.ClaimFixedDetailListVo;
import com.group.eams.pojo.vo.ClaimFixedListVo;
import com.group.eams.service.AssetClaimService;
import com.group.result.Result;
import com.group.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产申领表(AssetClaim)表控制层
 *
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetClaim")
public class AssetClaimController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetClaimService assetClaimService;

    /**
     * 查询资产申领信息列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result<List<AssetClaimListVo>> findAssetClaimByWhere(AssetClaimQueryDto assetClaimQueryDto) {
        Page<AssetClaimListVo> claimListVoPage = assetClaimService.findAssetClaimByWhere(assetClaimQueryDto);
        return Result.buildSuccess(claimListVoPage.getTotal(), claimListVoPage.getRecords());
    }

    /**
     * 按id查询资产申领信息
     */
    @RequestMapping(value = "/find", method = RequestMethod.GET)
    public Result<AssetClaim> find(@RequestParam Long id) {
        AssetClaim assetClaim = assetClaimService.getById(id);
        return Result.buildSuccess(assetClaim);
    }

    /**
     * 查询所有资产申领信息
     */
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result<List<AssetClaim>> findAll(){
        List<AssetClaim> tenementList = assetClaimService.list();
        return Result.buildSuccess(tenementList);
    }

    /**
     * 添加资产申领信息
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Result<Object> add(@RequestBody AssetClaim assetClaim) {
        boolean result = assetClaimService.save(assetClaim);
        return result ? Result.buildSuccess() : Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 修改资产申领信息
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<Object> update(@RequestBody AssetClaim assetClaim){
        boolean result = assetClaimService.updateById(assetClaim);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量添加资产申领信息
     */
    @RequestMapping(value = "/batchAdd",method = RequestMethod.POST)
    public Result<Object> batchAdd(@RequestBody List<AssetClaim> assetClaims){
        boolean result = assetClaimService.saveBatch(assetClaims);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量修改资产申领信息
     */
    @RequestMapping(value = "/batchUpdate",method = RequestMethod.POST)
    public Result<Object> batchUpdate(@RequestBody List<AssetClaim> assetClaims){
        boolean result = assetClaimService.updateBatchById(assetClaims);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 批量移除资产申领信息
     */
    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    public Result<Object> batchRemove(@RequestBody List<Long> ids){
        boolean result = assetClaimService.removeByIds(ids);
        return result ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 查询所有闲置资产信息
     */
    @RequestMapping(value = "/findClaimFixed",method = RequestMethod.GET)
    public Result<List<ClaimFixedListVo>> findClaimFixed(FixedAssetQueryDto fixedAssetQueryDto){
        Page<ClaimFixedListVo> claimFixedListVoPage = assetClaimService.findClaimFixedByWhere(fixedAssetQueryDto);
        return Result.buildSuccess(claimFixedListVoPage.getTotal(), claimFixedListVoPage.getRecords());
    }

    /**
     * 根据选择的id查询资产
     */
    @RequestMapping(value = "/addClaimFixedDetail",method = RequestMethod.POST)
    public Result<List<ClaimFixedDetailListVo>> addClaimFixedDetail(@RequestBody AssetPartDto assetPartDto){
        Page<ClaimFixedDetailListVo> claimFixedDetailListVoPage = assetClaimService.addClaimFixedDetail(assetPartDto);
        return Result.buildSuccess(claimFixedDetailListVoPage.getTotal(), claimFixedDetailListVoPage.getRecords());
    }

    /**
     * 按申请单号查询资产申领表下的所有资产信息
     */
    @RequestMapping(value = "/findClaimFixedDetail",method = RequestMethod.GET)
    public Result<List<ClaimFixedDetailListVo>> findClaimFixedDetail(ApplyNumFixedAssetQueryDto applyNumFixedAssetQueryDto){
        Page<ClaimFixedDetailListVo> claimFixedDetailListVoPage = assetClaimService.findClaimFixedDetail(applyNumFixedAssetQueryDto);
        return Result.buildSuccess(claimFixedDetailListVoPage.getTotal(), claimFixedDetailListVoPage.getRecords());
    }

    /**
     * 根据申请单号和assetId删除
     */
    @RequestMapping(value = "/deleteByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchDeleteIdsDto batchDeleteIdsDto){
        int result = assetClaimService.deleteByApplicationNum(batchDeleteIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号和assetId修改
     */
    @RequestMapping(value = "/updateByAssetIds", method = RequestMethod.POST)
    public Result<Object> batchDeleteByAssetIds(@RequestBody BatchUpdateIdsDto<AssetClaim> batchUpdateIdsDto){
        int result = assetClaimService.updateByApplicationNum(batchUpdateIdsDto);
        return result > 0 ? Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    /**
     * 根据申请单号查询
     */
    @RequestMapping(value = "/findByNum",method = RequestMethod.GET)
    public Result<AssetClaim> findByNum(@RequestParam String applicationNum) {
        AssetClaim assetClaim = assetClaimService.findClaimByNum(applicationNum);
        return Result.buildSuccess(assetClaim);
    }
}

